package br.ufrj.xml.model.persistence.dao.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.List;

import br.ufrj.xml.model.persistence.dao.SchemaDAO;
import br.ufrj.xml.model.persistence.entity.SchemaVO;
import br.ufrj.xml.model.persistence.entity.TableVO;

public class SchemaJdbcDAO extends GenericJdbcDAO<SchemaVO> implements SchemaDAO {

	private static final String BASIC_QUERY = "select nspname from pg_namespace";
	
	public SchemaJdbcDAO(Connection connection) {
		super(connection);
	}
	
	public SchemaVO mapRow(ResultSet resultSet) throws SQLException {
		int i = 1;
		SchemaVO schemaVO = new SchemaVO();
		schemaVO.setName(resultSet.getString(i++));
		schemaVO.setTables(new HashMap<String,TableVO>());
		return schemaVO;
	}

	public int count() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void create(SchemaVO entity) {
		// TODO Auto-generated method stub
		
	}

	public void delete(Integer id) {
		// TODO Auto-generated method stub
		
	}

	public List<SchemaVO> findAll() {
		return query(BASIC_QUERY + " WHERE upper(nspname) like '%_DTD%'");
	}

	public List<SchemaVO> findPageByPage(int firstResult, int maxResults) {
		// TODO Auto-generated method stub
		return null;
	}

	public SchemaVO read(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	public void update(SchemaVO entity) {
		// TODO Auto-generated method stub
		
	}

	public List<SchemaVO> findByName(String nmSchema) {
		List<SchemaVO> list = query(BASIC_QUERY + " WHERE upper(nspname) = ?", 
				new Object[]{ nmSchema },
				new int[]{ Types.VARCHAR });
		return list;
	}

}
